package com.qf.servlet;

import com.qf.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Ypl
 * @version V1.0
 * @Project September-mavens
 * @Package com.qf.servlet
 * @Description:
 * @Date 2022/9/29 17:26
 */
@SuppressWarnings("all")
@Controller
public class ParmServlet {
    /**
     * serlvet方式接收
     */
    @RequestMapping("/param1")
    public String testParam1(HttpServletRequest request){
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        System.out.println(id);
        System.out.println(name);
        return "skip";
    }

    /**
     *参数接收(普通类型接收)
     */
    @RequestMapping("/param2")
    public String testParam2(Integer id,String name){
        System.out.println(id);
        System.out.println(name);
        return "skip";
    }

    /**
     * 参数接受(对象接收)
     */
    @RequestMapping("/param3")
    public String testParam3(User user){
        System.out.println(user);
        return "skip";
    }

    /**
     * 参数接受(list 接收)
     */
    @RequestMapping("/param4")
    //因为List是接口，所以没有办法再括号中，没有办法让spring去new 对象
    public String testParam4(@RequestParam("list") List<String> list){
        System.out.println(list);
        return "skip";
    }

    /**
     * 参数接收(数组接收)
     * 接收时候的参数名称要和传来的值的名称相同
     */
    @RequestMapping("/param5")
//    public String testParam5(String[] arr){
    public String testParam5(String[] hobby){
        System.out.println(hobby);
        return "skip";
    }
    @RequestMapping("/param6")
    public String testParam6(Integer id , @RequestParam(value = "name",required = true,defaultValue = "heisanshignuirshbgiubdfru")String name){
        System.out.println(id);
        System.out.println(name);
        return "skip";
    }
}
